Project Overview :
● NumPy is an essential module for carrying out data science operations efficiently.
● NumPy stands for Numerical Python.
Matplotlib: Visualization with Python
● Matplotlib is a comprehensive library for creating static, animated, and interactive visualizations in Python. Matplotlib makes easy things easy and hard things possible. An object-oriented plotting library. A procedural interface is provided by the companion pyplot module, which may be imported directly. Eg: import matplotlib.pyplot as plt
Matplotlib Application Interfaces (APIs)
● Matplotlib has two major application interfaces, or styles of using the library:
● An explicit "Axes" interface that uses methods on a Figure or Axes object to create other Artists, and build a visualization step by step. This has also been called an "object-oriented" interface.
● An implicit "pyplot" interface that keeps track of the last Figure and Axes created, and adds Artists to the object it thinks the user wants.
Syntax : numpy.random.uniform()
● Draw samples from a uniform distribution. Any value within the given interval is equally likely to be drawn by uniform
numpy.random.uniform(low, high, size).
Histogram
● A histogram is a chart that plots the distribution of a numeric variable's values as a series of bars, hist() function in pyplot module of matplotlib library is used to plot a histogram. Each bar typically covers a range of numeric values called a bin or class.
Requirements :
● Python
● VS code
● Library – numpy and matplotlib
Code :
import numpy import matplotlib.pyplot as plt x = numpy.random.normal(5.0, 1.0, 100000) print(x) plt.hist(x, 100) plt.show()
Code Explanation :
● import numpy =>import numpy as np and use it in python. In command prompt or VS code terminal run the below pip command to install numpy library,
● pip3 install numpy # For Python version 3
● import matplotlib.pyplot as plt import matplotlib and use it in python. In command prompt or VS code terminal run the below pip command to install matplotlib library,
● pip3 install matplotlib
● Here pyplot() is the most important function in matplotlib library, which is used to plot 2D data.
● x = numpy.random.normal(5.0, 1.0, 100000) Draw the samples
● print (x)
● plt.hist(x,100) => plot a histogram.
● plt.show()
● Run the code.
Output :
● After running the code, output of the terminal as given below,
● Graph was generated in the plot.